﻿
Pages_Report_ReportInGame = new function () {
    this.ObjSearch = {
        AccountId: -1,
        TypeId: -1,
        AccountName: '',
        FromDate: '1/1/2012',
        ToDate: '1/1/2030',
        TypeTrans: -1,
        TypeMoney: -1,
        Result:-1
    };
    

    this.m_objPageInGame = new VtcPaging("divInGamePaging", "Pages_Report_ReportInGame.bindData", "pagingCss", 10, CONSTANT.PAGE_DISPLAY);
    this.getOptionSearch = function() {
        this.ObjSearch.AccountId = parseInt($("#txtAccountId").val());
        this.ObjSearch.AccountId = this.ObjSearch.AccountId > 0 ? this.ObjSearch.AccountId : -1;        
        
        this.ObjSearch.TypeId = $("#ddlTypeId").val();

        this.ObjSearch.AccountName = $("#txtAccountName").val();
        this.ObjSearch.FromDate = $("#txtFromDate").val();
        this.ObjSearch.ToDate = $("#txtToDate").val();
        
        this.ObjSearch.TypeTrans = $("#ddlTypeTransaction").val();
        this.ObjSearch.TypeMoney = $("#ddlTypeMoney").val();
        this.ObjSearch.Result = $("#ddlResult").val();
    };
    this.documentReady = function () {
        this.getOptionSearch();
        this.showMap(false);
        this.bindData(1, this.m_objPageInGame.pageSize);
        
    };

    this.bindData = function (_cur, _ps) {        
        Loading.showProcess();        
        $.ajax({
            type: "GET",
            url: "/handler/HandlerReport.ashx",
            data: {
                accountId: this.ObjSearch.AccountId, typeId: this.ObjSearch.TypeId, accountName: this.ObjSearch.AccountName,
                fromDate:this.ObjSearch.FromDate ,toDate:this.ObjSearch.ToDate,
                sessionStatus:this.ObjSearch.TypeTrans ,betUnit:this.ObjSearch.TypeMoney,finishStatus:this.ObjSearch.Result,
                currentPage: _cur, pageSize: _ps, t: "rptInGame"
            },
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            cache: false,
            success: function (data) {
                Pages_Report_ReportInGame.processData(data, _cur);
                Loading.closeProcess();
            }
        });

    };

    this.processData = function (data, _cur) {
        $("#spTotalAdmin").html('(' + data.TotalRecord.toString() + ')');
        
        $("#tdTotalAuBet").html(COMMON.formatMoney(data.TotalAuBet));
        $("#tdTotalAgBet").html(COMMON.formatMoney(data.TotalAgBet));
        $("#tdTotalAuBonus").html(COMMON.formatMoney(data.TotalAuCollect));
        $("#tdTotalAgBonus").html(COMMON.formatMoney(data.TotalAgCollect));               
        
        $("#divInGame").setTemplateURL("/Template/Pages/Report/rptInGame.htm");
        $("#divInGame").processTemplate(data);
        Pages_Report_ReportInGame.setStyleRow("#divInGame");
        Pages_Report_ReportInGame.m_objPageInGame.bindPaging(_cur, data.TotalRecord);
        if (data.TotalRecord <= Pages_Report_ReportInGame.m_objPageInGame.pageSize) {
            $("#divInGamePaging").attr('style', 'display:none');
        }
        else {
            $("#divInGamePaging").attr('style', 'display:block');
        }
    };
    
    this.bindMapList = function () {
        Loading.showProcess();
        $.ajax({
            type: "GET",
            url: "/handler/HandlerReport.ashx",
            data: {
                accountId: this.ObjSearch.AccountId, typeId: this.ObjSearch.TypeId, accountName: this.ObjSearch.AccountName,
                fromDate: this.ObjSearch.FromDate, toDate: this.ObjSearch.ToDate,
                sessionStatus: this.ObjSearch.TypeTrans, betUnit: this.ObjSearch.TypeMoney, finishStatus: this.ObjSearch.Result,
                 t: "rptMapInGame"
            },
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            cache: false,
            success: function (data) {
                Loading.closeProcess();
                $("#divMapInGame").setTemplateURL("/Template/Pages/Report/rptMapInGame.htm");
                $("#divMapInGame").processTemplate(data);                
            }
        });

    };
    $("#btnShowmap").live('click', function () {
        Pages_Report_ReportInGame.showMap(true);

    });
    $("#btnShowList").live('click', function () {
        Pages_Report_ReportInGame.showMap(false);

    });
    $("#btnSearch").live('click', function () {
        Pages_Report_ReportInGame.documentReady();
        
    });
    this.showMap = function(isShow) {
        if (isShow) {
            $("#divListInGame").hide();
            $("#divMapInGame").show();
            this.bindMapList();
        } else {
            $("#divListInGame").show();
            $("#divMapInGame").hide();
        }
    };

    this.setStyleRow = function (m_selParent) {
        var m_stt = 0;
        $('#divItem', m_selParent).each(function () {
            m_stt++;
            if ((m_stt % 2) == 0) {
                $(this.parentNode).addClass('even');
            }
            else {
                $(this.parentNode).addClass('odd');
            }
        });
    };       
}